--荒碎苦哀
local huangsuikuai = fk.CreateSkill {
    name = "mcdh_huangsuikuai"
}

local U = require "packages/utility/utility"
local lib = require "packages/mcdh/lib"

huangsuikuai:addEffect(fk.TargetSpecified,{
    can_trigger = function(self, event, target, player, data)
        return  player:hasSkill(self) and player == target and data.firstTarget and data.card.is_damage_card
    end,
    on_cost = function(self,event,target,player,data)
        local room = player.room
        local targets = table.filter(AimGroup:getAllTargets(data.tos), function(pid) return not room:getPlayerById(pid):isNude() end)
        if #targets == 0 then return end
        local tos = room:askForChoosePlayers(player, targets, 1, 1, "#huangsuikuai-choose", self.name, true)
        if #tos > 0 then
            self.cost_data = room:getPlayerById(tos[1])
            return true
        end
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        local card_event = room.logic:getCurrentEvent():findParent(GameEvent.UseCard)
        local ids =  room:askForCardsChosen(player, self.cost_data,1,self.cost_data.hp ,"he", self.name)
        room:throwCard(ids, self.name, self.cost_data, player)
        local red = {}
        for _,id in ipairs(ids) do
            if Fk:getCardById(id).color == Card.Red then
                table.insertIfNeed(red,id)
            end
        end
        card_event.huangsuikuai_num = #red
        card_event.huangsuikuai_tos = self.cost_data
    end,
})

huangsuikuai:addEffect(fk.CardUseFinished,{
    is_delay_effect = true,
    can_trigger = function(self, event, target, player, data)
        if player ~= target then return false end
        local card_event = player.room.logic:getCurrentEvent():findParent(GameEvent.UseCard, true)
        return card_event and card_event.huangsuikuai_tos
    end,
    on_cost = function(self,event,target,player,data)
        return true
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        local card_event = player.room.logic:getCurrentEvent():findParent(GameEvent.UseCard, true)
        if not card_event.huangsuikuai_tos.dead then
            card_event.huangsuikuai_tos:drawCards(card_event.huangsuikuai_num, self.name)
        end
    end
})

Fk:loadTranslationTable {
    ["mcdh_huangsuikuai"] = "荒碎苦哀",
    [":mcdh_huangsuikuai"] = "当你使用伤害牌指定目标后，你可以弃置其中一名目标角色至多等同于其体力值数张牌,此牌结算后，其摸X张牌。(X为其因此法弃置的红色牌数)",
    ["#huangsuikuai-choose"] = "荒碎苦哀:弃置其中一名目标角色至多等同于其体力值数张牌"
}

return huangsuikuai